#include "CardGame.h"

#include <iostream>
using std::cout;
using std::endl;

CardGame::CardGame(Console& console, Renderer& renderer)
	: mRenderer(renderer), effectPool(), spellPool(effectPool), characterPool(spellPool), board(characterPool) {
	console.addFunction("start", [this](vector<Parameter>& parameters) -> string {
		initialize();
		return "";
	});
	console.addFunction("exit", [this](vector<Parameter>& parameters) -> string {
		terminate();
		return "";
	});
	console.addFunction("update", [this](vector<Parameter>& parameters) -> string {
		mRenderer.render(board);
		return "";
	});
	
	console.addFunction("cast", std::bind(&CardGame::cast, this, std::placeholders::_1));
}

void CardGame::initialize() {
	cout << "initialize!" << endl;
	effectPool.loadFile("Effect.txt");
	spellPool.loadFile("Spell.txt");
	characterPool.loadFile("Character.txt");
	board.init();
}

void CardGame::terminate() {
	cout << "terminate!" << endl;
}

string CardGame::cast(vector<Parameter>& parameters) {
	string a, b, spell;
	parameters[0].to(a);
	parameters[1].to(b);
	parameters[2].to(spell);
	return (a + b + spell);
}